export const toBranchText = (nodeConfig, index, formIdObj) => {
	var { conditionList, groupMode,groupRelationMode,groupRelation } = nodeConfig.conditionNodes[index];
	if (conditionList.length == 0) {
		return (index == nodeConfig.conditionNodes.length - 1) ? '其他条件进入此流程' : '请设置条件'
	} else {
		var groupConArr = []
		let groupConArr1 = []
		for (var groupCondition of conditionList) {
			let mode = groupCondition.mode;
			let param = {
				groupName:groupCondition.groupName,
				s:''
			}
			var conArr = [];
			for (var con of groupCondition.conditionList) {
				const { key, expression, value,keyType,comments } = con;
				if (!key) {
					continue
				}
				if(keyType == 'expression'){
					conArr.push(comments)
				}
				else{
					let valueElement = formIdObj.value[key];
					var name = valueElement.name;
					var valueShow = value;
					if (valueElement.type === 'SelectUser' || valueElement.type === 'SelectDept' || valueElement.type === 'SelectMultiUser' || valueElement.type === 'SelectMultiDept') {
						valueShow = value.map(res => res.name).join(",")
					} else if (valueElement.type === 'SingleSelect') {
						valueShow = value.map(res => res.value).join(",")
					} else {
						if (!valueShow && valueShow !== 0) {
							valueShow = '?'
						}
					}
					if (expression === '==') {
						conArr.push(name + " 等于 " + valueShow);
					} else if (expression === 'in') {
						conArr.push(name + " 属于 " + valueShow);
					} else if (expression === 'notin') {
						conArr.push(name + " 不属于 " + valueShow);
					} else if (expression === '!=') {
						conArr.push(name + " 不等于 " + valueShow);
					} else if (expression === '>') {
						conArr.push(name + " 大于 " + valueShow);
					} else if (expression === '>=') {
						conArr.push(name + " 大于等于 " + valueShow);
					} else if (expression === '<') {
						conArr.push(name + " 小于 " + valueShow);
					} else if (expression === '<=') {
						conArr.push(name + " 小于等于 " + valueShow);
					} else if (expression === 'contain') {
						conArr.push(name + " 包含 " + valueShow);
					} else if (expression === 'notcontain') {
						conArr.push(name + " 不包含 " + valueShow);
					}
				}
			}
			if (mode) {
				let s = conArr.join(" 且 ");
				if (conArr.length > 0) {
					param.s = s
					groupConArr.push('(' + s + ')')
					groupConArr1.push(param)
				}
			} else {
				let s = conArr.join(" 或 ");
				if (conArr.length > 0) {
					param.s = s
					groupConArr.push('(' + s + ')')
					groupConArr1.push(param)
				}
			}
		}
		if(groupRelationMode){
			let arr = JSON.parse(JSON.stringify(groupRelation))
			arr.forEach(ele => {
				groupConArr1.forEach(item=>{
					if(item.groupName == ele.name){
						ele.name = item.s
					}
				})
			});
			 let arrnew = arr.map((obj,index) => {
				return obj.name;
			}).join('')
			return arrnew
		}
		return groupConArr.length > 0 ? groupConArr.join(groupMode ? " 且 " : " 或 ") : (index == nodeConfig.conditionNodes.length - 1 ? '默认条件' : '请设置条件')
	}
}
export const setApproverStr = (nodeConfig) => {
	if (nodeConfig.assignedType == 1) {
		//指定成员
		if (nodeConfig.nodeUserList.length >= 1) {
			return nodeConfig.nodeUserList.map(res => res.name).join(",")

		} else {
			return ""

		}
	} else if (nodeConfig.assignedType == 10) {
		//指定部门主管
		if (nodeConfig.nodeUserList.length >= 1) {
			return nodeConfig.nodeUserList.map(res => res.name).join(",")
		} else {
			return ""

		}
	} else if (nodeConfig.assignedType == 11) {
		//系统自动拒绝
		return "系统自动拒绝"
	} else if (nodeConfig.assignedType == 3) {
		//指定角色
		if (nodeConfig.nodeUserList.length >= 1) {
			return nodeConfig.nodeUserList.map(res => res.name).join(",")
		} else {
			return ""
		}
	} else if (nodeConfig.assignedType == 2) {
		return nodeConfig.deptLeaderLevel == 1 ? '直接部门主管' : '第' + nodeConfig.deptLeaderLevel + '级部门主管'

	} else if (nodeConfig.assignedType == 4) {
		//发起人自选
		return "发起人自选"

	} else if (nodeConfig.assignedType == 5) {
		return "发起人自己"
	} else if (nodeConfig.assignedType == 7) {
		return '到第' + nodeConfig.deptLeaderLevel + '级部门主管终止'
	} else if (nodeConfig.assignedType == 8 && nodeConfig.formUserId.length > 0) {
		//表单-人员
		return '表单人员：' + nodeConfig.formUserName
	} else if (nodeConfig.assignedType == 9 && nodeConfig.formUserId.length > 0) {

		let deptUserType = nodeConfig.deptUserType;
		let deptUserTypeShow = '主管'
		if (deptUserType === 'allUser') {
			deptUserTypeShow = '所有人员'
		}

		//表单-部门
		return '表单部门：' + nodeConfig.formUserName + " 的" + deptUserTypeShow
	}
	return "";
}
export const arrToStr = (arr) => {
	if (arr) {
		if (arr.length == 0) {
			return '所有人'
		}
		return arr.map(item => {
			return item.name
		}).toString()
	}
}
export const copyerStr = (nodeConfig) => {
	if (nodeConfig.nodeUserList?.length != 0) {
		return arrToStr(nodeConfig.nodeUserList)
	}
	else {
		return '请选择抄送人'
	}
}